package com.moodbox.server.config;

import com.moodbox.server.common.interceptor.RoleAuthInterceptor;
import com.moodbox.server.common.interceptor.TokenAuthInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {

    private final RoleAuthInterceptor roleAuthInterceptor;
    private final TokenAuthInterceptor tokenAuthInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // Token认证拦截器优先级最高
        registry.addInterceptor(tokenAuthInterceptor)
            .addPathPatterns("/**")
            .excludePathPatterns(
                "/user/wx-login",  // 微信登录接口
                "/error",           // 错误处理接口
                "/actuator/**",     // Spring Boot Actuator
                "/swagger-ui/**",   // Swagger UI
                "/v3/api-docs/**"   // OpenAPI文档
            );

        // 角色权限拦截器
        registry.addInterceptor(roleAuthInterceptor)
            .addPathPatterns("/sensitive-words/**")  // 敏感词管理接口
            .addPathPatterns("/admin/**")            // 管理员接口
            .excludePathPatterns("/sensitive-words/check");  // 检查接口不需要权限
    }
} 